package com.tongguan.paypos.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.tongguan.paypos.R;
import com.tongguan.paypos.base.BaseFragment;
import com.tongguan.paypos.entity.TransInfo;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Joylive on 2016/12/13 .
 */

public class ResultHYCFragment extends BaseFragment {

    public static final String EXCHANGE_RESULT = "exchange_result";
    public static final String EXCHANGE_CARD_NO = "exchange_cardNo";

    @BindView(R.id.tv_member_card_no)
    TextView mTvMemberCardNo;
    @BindView(R.id.tv_recharge_order_id)
    TextView mTvRechargeOrderId;
    @BindView(R.id.tv_recharge_up_order)
    TextView mTvRechargeUpOrder;
    @BindView(R.id.tv_recharge_amount)
    TextView mTvRechargeAmount;
    @BindView(R.id.btn_result)
    Button mBtnResult;

    private TransInfo transInfo;
    private String cardNo;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_hyc_result, container, false);
        ButterKnife.bind(this, rootView);
        Bundle arguments = getArguments();
        if (arguments != null) {
            transInfo = arguments.getParcelable(EXCHANGE_RESULT);
            cardNo = arguments.getString(EXCHANGE_CARD_NO);
        }
        mTvMemberCardNo.setText(cardNo);
        mTvRechargeOrderId.setText(transInfo.getOrderId());
        mTvRechargeUpOrder.setText(transInfo.getUpOrderId());
        mTvRechargeAmount.setText(String.valueOf(transInfo.getPayMoney()));
        mBtnResult.setOnClickListener(v -> frmCtx.finish());
        setTimer(mHandler, 1);
        return rootView;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int m = (Integer) msg.obj;
            mBtnResult.setText("确   认" + " (" + m / 1000 + ")");
            if (m / 1000 == 0) {
                mTime.cancel();
                mBtnResult.callOnClick();
            }
        }
    };
}
